﻿namespace ElisVK.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Data;
    using Utils;

    public class BalloonViewModel : BindableObject
    {
        private readonly ElisVKViewModel _elisVKViewModel;

        private NotificationActions _action;

        private static Dictionary<NotificationActions, string> ActionIcons = new Dictionary<NotificationActions, string>
            {
                {NotificationActions.Play, "Play.png"},
                {NotificationActions.Pause, "Pause.png"},
                {NotificationActions.Volume, "Volume_3.png"},
                {NotificationActions.Shuffle, "ShuffleOn.png"}
            };

        public BalloonViewModel(ElisVKViewModel elisVKViewModel, NotificationActions action)
        {
            _elisVKViewModel = elisVKViewModel;
            Action = action;
        }

        private ElisVKViewModel ElisVKViewModel
        {
            get { return _elisVKViewModel; }
        }

        private Audio CurrentAudio
        {
            get { return ElisVKViewModel.SelectedAudio; }
        }

        public NotificationActions Action
        {
            get
            {
                return _action;
            }

            set
            {
                _action = value;

                switch (_action)
                {
                    case NotificationActions.Play:
                    case NotificationActions.Pause:
                        {
                            if (CurrentAudio == null)
                                break;

                            PrimaryText = CurrentAudio.Artist;
                            SecondaryText = CurrentAudio.Title;
                        }
                        break;
                    case NotificationActions.Volume:
                        {
                            PrimaryText = string.Format("Volume: {0}%", (int) (ElisVKViewModel.Volume * 100));
                        }
                        break;
                    case NotificationActions.Info: 
                        {
                            if (CurrentAudio == null)
                            {
                                PrimaryText = "ElisVK player";
                                SecondaryText = string.Empty;
                                break;
                            }

                            PrimaryText = CurrentAudio.Artist;
                            SecondaryText = CurrentAudio.Title;

                            _action = ElisVKViewModel.IsPlaying ? NotificationActions.Play : NotificationActions.Pause;
                        }
                        break;
                }

                OnPropertyChanged("Action");
                OnPropertyChanged("PrimaryText");
                OnPropertyChanged("SecondaryText");
                OnPropertyChanged("ActionIcon");
            }
        }

        public string PrimaryText { get; set; }

        public string SecondaryText { get; set; }

        public ImageSource ActionIcon
        {
            get
            {
                if (ActionIcons.ContainsKey(Action))
                    return
                        new BitmapImage(
                            new Uri("/BasicSkin;component/Res/" + ActionIcons[Action], UriKind.RelativeOrAbsolute));

                return null;
            }
        }
    }
}
